<?php

class timeType extends typeInterface{
    
    public $form_type = "text";
    public function validate($campo, &$time){
        if(!$this->checktime($time)){
            $this->setErrorMessage("Tempo inválido");
            return false;
        }
        return true;
    }
    
     public function formulario($name, $array, $caption = "", $value = "", $desc = ""){
        $this->form->text($name, $caption, $value, $desc);
    }
    
    // valida hora 23:59
    private function checktime(&$time){
       $t = explode(':',$time);
       $hour = $minute = $segundo = "00";
       $hour    = isset($t[0])?$t[0]:"00"; 
       $minute  = isset($t[1])?$t[1]:"00"; 
       $segundo = isset($t[2])?$t[2]:"00";
       
       $time = "$hour:$minute:$segundo";
       if (($hour > -1 && $hour < 24) && ($minute > -1 && $minute < 60) && (($segundo > -1 && $segundo < 60)||$segundo == ""))
           return true;
       return false;
    } 
}

?>
